window.onload = function () {
    //获取轮播图的数据
    getqueryadmin()
        .then(res => {
            // 对服务器的数据进行加工处理
            const result = res.msg.map(item => {
                return item.url
            })
            //渲染
            const banner = document.getElementById("banner")
            result.forEach(item => {
                let str = `
            <div class="swiper-slide">
                <img src="${item}" alt="">
            </div>
            `
                banner.innerHTML += str;
            })

            //让轮播图轮播
            new Swiper('.swiper', {
                loop: true, // 循环模式选项

                // 如果需要分页器
                pagination: {
                    el: '.swiper-pagination',
                },

                // 如果需要前进后退按钮
                navigation: {
                    nextEl: '.swiper-button-next',
                    prevEl: '.swiper-button-prev',
                },
            })
        })

    //获取的是学校专业
    getsubject()
        .then(res => {
            const subject = document.querySelector(".subject")
            // console.log(res);
            const res1 = res.msg.map(item => item.subject)
            //浅拷贝
            const result = [...new Set(res1)]
            result.forEach(item => {
                let str = `
                <div>
                    <p><img src="http://wap.mobiletrain.org/imgs2022/m-city/c1_1.png" alt=""></p>
                    <p>${item}</p>
                </div>
                `
                subject.innerHTML += str;
            })
        })

    //获取所有的学生信息
    getstudent()
        .then(res => {
            const student = document.querySelector(".home>.content>.student")
            localStorage.setItem("studentInfo", JSON.stringify(res.msg))
            //渲染四条数据
            const result = res.msg.slice(0, 4)
            result.forEach(item => {
                let str = `
                <div onclick="window.location.href = './detail.html?id=${item.sid}'">
                    <p><img data-src="${item.url}" class="lazyload" /></p>
                    <p>姓名:${item.sname}</p>
                    <p>性别:${item.gender}</p>
                    <p>邮箱:${item.email.slice(0, 8)}...</p>
                </div>
                `
                student.innerHTML += str;
            })
        })
}